package org.example.ui.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.application.UrlShortenerStatsService;
import org.example.domain.model.entity.url.req.UrlShortenerGroupStatsAccessRecordReq;
import org.example.domain.model.entity.url.req.UrlShortenerGroupStatsReq;
import org.example.domain.model.entity.url.req.UrlShortenerStatsAccessRecordReq;
import org.example.domain.model.entity.url.req.UrlShortenerStatsReq;
import org.example.web.result.ResultInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/api/stats/v1")
@Tag(name = "短链接监控" ,description = "短链接监控")
public class UrlShortenerStatsController {

    private final UrlShortenerStatsService urlShortenerStatsService;


    @GetMapping()
    @Operation(summary = "访问单个短链接指定时间内监控数据")
    public ResultInfo urlShortenerStats(UrlShortenerStatsReq urlShortenerStatsReq) {
        return ResultInfo.success(urlShortenerStatsService.oneUrlShortenerStats(urlShortenerStatsReq));
    }


    @GetMapping("/group")
    @Operation(summary = "访问分组短链接指定时间内监控数据")
    public ResultInfo groupUrlShortenerStats(UrlShortenerGroupStatsReq urlShortenerGroupStatsReq) {
        return ResultInfo.success(urlShortenerStatsService.groupUrlShortenerStats(urlShortenerGroupStatsReq));
    }

    @GetMapping("/access-record")
    @Operation(summary = "访问单个短链接指定时间内访问记录监控数据")
    public ResultInfo urlShortenerStatsAccessRecord(UrlShortenerStatsAccessRecordReq urlShortenerStatsAccessRecordReq) {
        return ResultInfo.success(urlShortenerStatsService.urlShortenerStatsAccessRecord(urlShortenerStatsAccessRecordReq));
    }

    @GetMapping("/access-record/group")
    @Operation(summary = "访问分组短链接指定时间内访问记录监控数据")
    public ResultInfo groupShortLinkStatsAccessRecord(UrlShortenerGroupStatsAccessRecordReq urlShortenerGroupStatsAccessRecordReq) {
        return ResultInfo.success(urlShortenerStatsService.groupUrlShortenerStatsAccessRecord(urlShortenerGroupStatsAccessRecordReq));
    }
}
